Skip to content

feat: allow to get results as json#284

Merged
sdn4z merged 1 commit into
elementsinteractive:mainfrom
sdn4z:error-display
Aug 30, 2025
Merged

feat: allow to get results as json#284
sdn4z merged 1 commit into
elementsinteractive:mainfrom
sdn4z:error-display

Conversation

@sdn4z
Copy link
Copy Markdown
Collaborator

@sdn4z sdn4z commented Aug 29, 2025

Introduces --json flag to return the results as a json.

It no longer uses click.echo, for some reason it is not captured in the output and it's impossible to test.

Another important addition here is that check_dependencies now returns an object of the new class TyposquatCheckResultList. This breaks previous implementations of those using twyn as a package.

It also renames candidate_dependency to dependency and similar_results to similarities from the TyposquatCheckResult model.

BREAKING CHANGE
closes #283

@sdn4z sdn4z requested a review from scastlara as a code owner August 29, 2025 14:00
@github-actions github-actions Bot added feature and removed feature labels Aug 29, 2025
@github-actions github-actions Bot added feature and removed feature labels Aug 29, 2025
@sdn4z sdn4z changed the title feat: allow to get results as json feat!: allow to get results as json Aug 29, 2025
@github-actions github-actions Bot removed the feature label Aug 29, 2025
@scastlara
Copy link
Copy Markdown
Collaborator

It no longer uses click.echo, for some reason it is not captured in the output and it's impossible to test.

What does this mean? Why did we need to ditch click for the output?

candidate_dependency: str
similar_dependencies: list[str] = field(default_factory=list)
dependency: str
similarities: list[str] = []
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these really similarities? Why the rename?

Copy link
Copy Markdown
Collaborator Author

@sdn4z sdn4z Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these really similarities?

I think they are, no?

Why the rename?

I wanted to make it shorter for a better experience when working with the json.

I'm open to alternatives though!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite pedantic 😆 but to me similarities are "the attributes or qualities that make something like something else".

So in this example the similarities are the "shared letters", and the "something else" are the similar_depdendencies.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would calling it similars work for you?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Comment thread src/twyn/trusted_packages/trusted_packages.py
@sdn4z
Copy link
Copy Markdown
Collaborator Author

sdn4z commented Aug 29, 2025

It no longer uses click.echo, for some reason it is not captured in the output and it's impossible to test.

What does this mean? Why did we need to ditch click for the output?

You can find here an example https://github.com/elementsinteractive/twyn/pull/284/files#diff-ae0b15b531bda07c4292b5e4d8acb8b370f8a2e8c511a85ba548ad7d4491cc22R245

click is not returning any output when we use click.echo, therefore we can't test the message that we get back.

EDIT: I've deleted a fixture that was causing this issue. Thanks for pointing out!

@sdn4z sdn4z changed the title feat!: allow to get results as json feat: allow to get results as json Aug 29, 2025
@sdn4z sdn4z merged commit 8b09af6 into elementsinteractive:main Aug 30, 2025
12 checks passed
@sdn4z sdn4z deleted the error-display branch September 10, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show output as json

2 participants